package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.dto.AnnouncementDto;
import com.jiyun.model.xitong.Announcement;
import com.jiyun.service.IAnnouncementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.mapper.AnnouncementMapper;
import com.jiyun.model.xitong.dto.AnnouncementQuery;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 针对表【-Announcement】的业务操作的Service实现类
 *
 * @author ???
 * @since 2024-09-26
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {

    @Override
    public IPage<Announcement> getPageList(AnnouncementQuery query){
        //1.创建查询条件
        QueryWrapper<Announcement> qw = new QueryWrapper<>();
        //ToDo 查询条件
        //2.组件分页数据
        IPage<Announcement> page = new Page<>(query.getCurrentPage(), query.getPageSize());
        //3.查询
        baseMapper.selectPage(page,qw);
        //4.返回
        return page;
    }

    @Override
    public IPage<Announcement> findAllAnnouncement(AnnouncementDto announcementDto) {
        LambdaQueryWrapper<Announcement> wrapper=new LambdaQueryWrapper<>();
        IPage<Announcement> page=new Page<>(announcementDto.getPageNum(), announcementDto.getPageSize());
        //开始时间和结束时间区间查询
        if(announcementDto.getStartTime()!=null&&announcementDto.getEndTime()!=null){
            wrapper.between(Announcement::getReleaseTime,announcementDto.getStartTime(),announcementDto.getEndTime());
        }
        return baseMapper.selectPage(page, wrapper);
    }
}
